package org.example;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author：ygp
 * @Package：org.example
 * @Project：ServletApi
 * @name：HelloWorld
 * @Date：2023/12/14 14:12
 * @Filename：HelloWorld
 */

@WebServlet(name = "helloworld" ,urlPatterns = "/hello")
public class HelloWorld extends HttpServlet {
    public HelloWorld() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("111");
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("000");

        /**将内容输出到前台
         *         resp.getWriter().write("helloworld");
         *         resp.setCharacterEncoding("UTF-8");
         *         resp.setContentType("text/json");
         *         PrintWriter out = resp.getWriter();
         *         out.println("ceshi---");
         *         out.flush();
         *         out.close();
         */


        /**
         * 属性传递到jsp页面
         */
        req.setAttribute("attributes","hello from servlet");
        RequestDispatcher dispatcher = req.getRequestDispatcher("/out.jsp");
        dispatcher.forward(req,resp);
    }
    //通过restTemplate.exchange接收只能是void





}
